package com.ruoyi.place.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.place_type.domain.PlaceType;
import com.ruoyi.place_type.mapper.PlaceTypeMapper;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.place.mapper.PlaceMapper;
import com.ruoyi.place.domain.Place;
import com.ruoyi.place.service.IPlaceService;

/**
 * 场所信息Service业务层处理
 * 
 * @author 张富饶
 * @date 2025-05-18
 */
@Service
public class PlaceServiceImpl implements IPlaceService 
{
    @Autowired
    private PlaceMapper placeMapper;
    @Autowired
    private PlaceTypeMapper placeTypeMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 查询场所信息
     * 
     * @param id 场所信息主键
     * @return 场所信息
     */
    @Override
    public Place selectPlaceById(Long id)
    {
        Place place = placeMapper.selectPlaceById(id);
//        System.err.println(place);
        Long managerId = place.getManagerId();
        User user = userMapper.selectUserByUserId(managerId);
        place.setUser(user);
//        System.err.println(user);
        PlaceType placeType = place.getPlaceType();
        Long id1 = placeType.getId();
        PlaceType placeType1 = placeTypeMapper.selectPlaceTypeById(id1);
        place.setPlaceType(placeType1);
        System.err.println(place);
        return place;
    }

    /**
     * 查询场所信息列表
     * 
     * @param place 场所信息
     * @return 场所信息
     */
    @Override
    public List<Place> selectPlaceList(Place place)
    {
        return placeMapper.selectPlaceList(place);
    }

    /**
     * 新增场所信息
     * 
     * @param place 场所信息
     * @return 结果
     */
    @Override
    public int insertPlace(Place place)
    {
        place.setCreateTime(DateUtils.getNowDate());
        return placeMapper.insertPlace(place);
    }

    /**
     * 修改场所信息
     * 
     * @param place 场所信息
     * @return 结果
     */
    @Override
    public int updatePlace(Place place)
    {
        place.setUpdateTime(DateUtils.getNowDate());
        return placeMapper.updatePlace(place);
    }

    /**
     * 批量删除场所信息
     * 
     * @param ids 需要删除的场所信息主键
     * @return 结果
     */
    @Override
    public int deletePlaceByIds(Long[] ids)
    {
        return placeMapper.deletePlaceByIds(ids);
    }

    /**
     * 删除场所信息信息
     * 
     * @param id 场所信息主键
     * @return 结果
     */
    @Override
    public int deletePlaceById(Long id)
    {
        return placeMapper.deletePlaceById(id);
    }
}
